<template>
  <footer class="site-footer">
    <div class="footer-container">
      <div class="footer-content" v-if="footerData">
        <div class="footer-section">
          <h3>Contact Info</h3>
          <div class="contact-item" v-if="footerData.contact_info?.address">
            <div class="icon">📍</div>
            <div>
              <strong>Address</strong>
              <p>{{ footerData.contact_info.address }}</p>
            </div>
          </div>
          <div class="contact-item" v-if="footerData.contact_info?.email">
            <div class="icon">✉️</div>
            <div>
              <strong>Email</strong>
              <p><a :href="`mailto:${footerData.contact_info.email}`">{{ footerData.contact_info.email }}</a></p>
            </div>
          </div>
        </div>
        <div class="footer-section">
          <h3>Useful Links</h3>
          <ul class="links-list" v-if="footerData.useful_link_list && footerData.useful_link_list.length > 0">
            <li v-for="link in footerData.useful_link_list" :key="link.content_id">
              <a :href="link.content_url" target="_blank" rel="noopener noreferrer">{{ link.title }}</a>
            </li>
          </ul>
          <p v-else class="no-links"></p>
        </div>
      </div>
      <div class="footer-loading" v-else></div>
      <div class="footer-bottom">
        <p>Copyright {{ currentYear }} - {{ homeInfoData?.copyright || 'Multimodal Health Data and Aging Lab - SUSTech' }}</p>
      </div>
    </div>
  </footer>
</template>

<script>
import { getFooterData } from '@/utils/api'

export default {
  name: 'Footer',
  inject: ['homeInfo'],
  data() {
    return {
      currentYear: new Date().getFullYear(),
      footerData: null,
      loading: false,
      error: null
    }
  },
  computed: {
    homeInfoData() {
      return this.homeInfo ? this.homeInfo() : null
    }
  },
  async mounted() {
    await this.fetchFooterData()
  },
  methods: {
    async fetchFooterData() {
      this.loading = true
      try {
        this.footerData = await getFooterData()
      } catch (error) {
        console.error('获取Footer数据失败:', error)
        this.error = error.message
      } finally {
        this.loading = false
      }
    }
  }
}
</script>

<style scoped>
.site-footer {
  background-color: #5a5a5a;
  color: #b0b0b0;
  padding: 30px 0 0;
  margin-top: 50px;
}

.footer-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 30px;
}

.footer-content {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 60px;
  margin-bottom: 25px;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.footer-section h3 {
  font-size: 1.3em;
  margin-bottom: 25px;
  color: #fff;
  font-weight: normal;
}

.contact-item {
  display: flex;
  gap: 15px;
  margin-bottom: 25px;
  align-items: flex-start;
}

.contact-item .icon {
  font-size: 1.5em;
  min-width: 30px;
}

.contact-item strong {
  display: block;
  color: #fff;
  margin-bottom: 5px;
  font-size: 1em;
}

.contact-item p {
  margin: 0;
  line-height: 1.6;
  font-size: 0.95em;
}

.links-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.links-list li {
  margin-bottom: 12px;
}

.links-list a {
  color: #b0b0b0;
  transition: color 0.3s ease;
  font-size: 0.95em;
}

.links-list a:hover {
  color: #00bcd4;
}

.postal-code {
  margin-top: 5px;
  font-size: 0.9em;
  color: #999;
}

.contact-item a {
  color: #b0b0b0;
  text-decoration: none;
  transition: color 0.3s ease;
}

.contact-item a:hover {
  color: #00bcd4;
}

.address-image {
  max-width: 100%;
  height: auto;
  margin-top: 10px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.no-links {
  color: #999;
  font-size: 0.9em;
}

.footer-loading {
  text-align: center;
  padding: 40px 0;
  color: #b0b0b0;
}

.footer-bottom {
  text-align: center;
  padding: 15px 0;
  background-color: rgba(0, 0, 0, 0.2);
  margin: 0 -30px;
}

.footer-bottom p {
  margin: 0;
  color: #b0b0b0;
  font-size: 0.9em;
}

@media (max-width: 768px) {
  .footer-content {
    grid-template-columns: 1fr;
    gap: 40px;
  }
  
  .footer-container {
    padding: 0 15px;
  }
  
  .footer-bottom {
    margin: 0 -15px;
  }
}
</style>

